package jk.fox.common;

import jk.fox.common.exception.runtime.*;

/**
 * Rpc状态
 * @author cuichao
 * @Description: RpcStatus
 * @Date: create in 2020/6/7 0:24
 */
public class RpcStatus {

    public final static int OK = 200;

    public static boolean isOk(int code){
        return OK == code;
    }


    public static RpcRunException getBadRequestException(int code, String message){
        RpcRunException exception = null;
        RpcDict.RpcException rpcException = RpcDict.RpcException.find(code);
        switch (rpcException){
            case RpcCommonException:
                exception = new RpcRunException(code,message);
                break;
            case RpcSerializable:
                exception = new RpcSerializableException(message);
                break;
            case RpcModuleNotInit:
                exception = new RpcModuleNotInitException(message);
                break;
            case RpcRequestTimeOut:
                exception = new RpcRequestTimeoutException(message);
                break;
            case RpcServerNoRegistry:
                exception = new RpcServerNoRegistException(message);
                break;
            case RpcNoAvailableServer:
                exception = new RpcNoAvailableServerException(message);
                break;
            case RpcNotSupportService:
                exception = new RpcNotSupportServiceException(message);
                break;
            case RpcConnectionMaxRetry:
                exception = new RpcConnectRetryException(message);
                break;
            case RpcExceededMaxRetries:
                exception = new RpcExceededMaxRetriesException(message);
                break;
            default:
                exception = new RpcRunException(RpcDict.RpcException.RpcCommonException.getCode(),message);
                break;

        }
        return exception;
    }


}
